# 作者：石吴震
# 2024年12月28日16时07分59秒
# 474160957@qq.com


def interface_tuple():
    my_tuple = (1, 2, 3, 4, 5)
    your_tuple = (1, 2, 3, 4, 5)
    print(len(my_tuple))
    print(my_tuple .count(5))
    print(my_tuple.index(5))
    print(my_tuple[2:4])
    for item in my_tuple:
        print(item, end=' ')
    info_tuple=("阿毛",20,"男")
    print("%s年龄是%d 性别是%s" %(info_tuple))
    print(f'{info_tuple[0]}年龄是{info_tuple[1]} 性别是{info_tuple[2]}')
    my_list=[0,7,5,8,1]
    print(tuple(my_list))
    print(list(my_tuple))

def interface_dict():
    my_dict={'name':'阿毛',
             '年龄':'20',
             '性别':'True',
             '身高':'170'}
    your_dict={'name':'小明',
               '年龄':8,
               '性别':'男',
               '身高':140}
    print(my_dict['name'])
    my_dict['name']='小红'
    my_dict.pop('年龄')
    print(len(my_dict))  # 键数量
    my_dict.update(your_dict)  # 键值相同会被覆盖
    for k in my_dict:
        print("%s--%s" %(k,my_dict[k]),end=' ')
    xiaoming_list=[{'name':'阿毛',
             '年龄':'20',
             '性别':'True',
             '身高':'170'},
            {'name':'小明',
               '年龄':8,
               '性别':'男',
               '身高':140}]
    for info_dict in xiaoming_list:
        print(info_dict)

    print(my_dict)
    print(your_dict)

def interface_str():
    my_str = "hello hello"
    for c in my_str:
        print(c, end='')
    print(my_str.isspace())
    print(my_str.isalnum())
    print(my_str.isalpha())
    print(my_str.isdecimal())
    print(my_str.islower())
    print(my_str.isupper())
    print(my_str.startswith('he'))
    print(my_str.endswith('lo'))
    print(my_str.find('h', 2,5))  #找不到会返回-1
    print(my_str.rfind('o', 2,5)) # 从右边开始查找
    # print(my_str.index('o', 2,5)) # 与find()相同，但找不到会报错
    # print(my_str.rindex('h', 2,5))
    print(my_str.replace('hello', 'hi',1) )# 把string中的old_str替换成new_str，如果num指定，则替换不超过num次
    print(my_str.lower())
    print(my_str.upper())
    print(my_str.swapcase())
    print(my_str.lstrip('h'))
    print(my_str.rstrip('o'))
    print(my_str.strip('e'))
    it_str = "1 \n2 \n3 \n4 \n5 \n6 \n7 \n8\n 9 \n0"
    print(it_str.split(' ',5))
    print(it_str.splitlines())
    it_list = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
    print(' '.join(it_list)) #列表要是字符串类型的元素，才可以用join()方法，用空格连接
    print(my_str[2:5])
    print(my_str[2:])
    print(my_str[:5])
    print(my_str[:])
    print(my_str[::2])
    print(my_str[2:-1])
    print(my_str[-2:])
    print(my_str[::-1])

def interface_set():
    my_set={"apple","banana","cherry"}
    your_set={"google","microsoft","apple"}
    my_set.add("orange")
    x=my_set.copy()
    y=my_set.difference(your_set)
    my_set.difference_update(your_set)
    print(my_set)
    my_set.discard("banana")
    print(my_set)
    result=my_set.intersection(your_set)
    print(result)
    my_set.intersection_update(your_set)
    print(my_set)
    print(my_set.isdisjoint(your_set))
    print(my_set.issubset(your_set))
    print(my_set.issuperset(your_set))
    your_set.remove("google")
    print(your_set)
    n=my_set.symmetric_difference(your_set)
    print(n)
    my_set.symmetric_difference_update(your_set)
    print(my_set)
    z=my_set.union(your_set)
    print(z)
    my_set.union(your_set)
    print(my_set)


    print(y)
    print(x)
    print(my_set)

def interface_num_list(name,gender=True):  #必须保证缺省参数在末尾
    my_list = [1,7,3,6,5]
    my_list.sort()
    my_list.sort(reverse=True)
    gender_text = '男'
    if not gender :
        gender_text = '女'
    print(f'{name}的性别是{gender_text}')



if __name__ == '__main__':

    interface_tuple()
    interface_dict()
    interface_str()
    interface_set()
    interface_num_list('小明')